<?php

class BaseView {

    public $columnTypes = array();
    
    public function __construct()
	{
	    $sql = "SELECT * FROM " . $this->getTableName() . " LIMIT 1"; 
	    $result = TUtils::CriarResultSet($sql);
		
        $numcam = pg_num_fields($result);
                   
        if ( pg_num_rows($result) > 0 ){

           for ( $i = 0; $i < $numcam; $i++ ){
        	   $this->columnTypes[pg_field_name( $result, $i )] = pg_field_type( $result, $i );
           }
        }    
    }
    

	public function getTableName()
	{
		$class = get_class($this);
		return constant("{$class}::tablename");
	}
	
	public function listar( $criterio = null )
    {
    	
    	return TSqlSelect::simpleSelect( self::getTableName(), NULL, $criterio );
    	
    	/*$valor 		= ( isset( $criterio['valor'] ) ) 		? $criterio['valor'] : null;
    	$operador 	= ( isset( $criterio['operador'] ) ) 	? $criterio['operador'] : null;
    	$campo 		= ( isset( $criterio['campo'] ) ) 		? $criterio['campo'] : null;
    	$order 		= ( isset( $criterio['order'] ) ) 		? $criterio['order'] : 'asc';
    	$orderBy	= ( isset( $criterio['orderBy'] ) ) 	? $criterio['orderBy'] : null;
    	$campos		= ( isset( $criterio['campos'] ) ) 		? $criterio['campos'] : '*';
    	
    	$sql = "SELECT $campos FROM " . self::getTableName();
        
    	if (trim($valor) <> "" && $campo <> "0"){
        	if ($operador == "ilike")
               	$sql .= " WHERE $campo $operador '%$valor%' ";
           	else
               	$sql .= " WHERE $campo $operador '$valor' ";
            if ( $orderBy )
				$sql .= " ORDER BY $orderBy $order";
    	}
    	
    	return TUtils::CriarResultSet($sql);*/
		
    }	
	
}

?>